package com.bo.threadCreate;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @Author: gpb
 * @Date: 2024/7/13 21:59
 * @Description:
 */
public class ICallable implements Callable<Integer> {
    @Override
    public Integer call() throws Exception {
        int i = 0;
        for (; i < 100; i++) {
            System.out.println(Thread.currentThread().getState() + ":" + i);
        }
        return i;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ICallable iCallable = new ICallable();
        // 创建FutureTask用于接受结果
        FutureTask<Integer> futureTask = new FutureTask<>(iCallable);
        Thread a = new Thread(futureTask, "A");
        a.start();
        System.out.println("A线程执行的结果是：" + futureTask.get());
    }
}
